package com.tx.review.enumuation;

/**
 * @author ：tx
 * @version:
 */
public class EnumTest {
    public static void main(String[] args) {
        //创建枚举数组
        Day[] days=new Day[]{Day.MONDAY, Day.TUESDAY, Day.WEDNESDAY,
                Day.THURSDAY, Day.FRIDAY, Day.SATURDAY, Day.SUNDAY};

        /**
         * ordinal()
         * compareTo(E o)
         * equals(Object other)
         * getDeclaringClass()
         * name()
         * toString()
         * static valueOf(Class<T> enumType, String name)
        */

        for (Day day : days) {
            System.out.println("ordinal:" + day.ordinal());
        }
        System.out.println("==============================");
        //返回的结果是两个枚举ordinal之差： self.ordinal - other.ordinal;
        System.out.println("monday.compareTo(tuesday):" + days[0].compareTo(days[2]));

        System.out.println("==============================");
        System.out.println("monday.equals(monday):" + days[0].equals(days[0]));

        System.out.println("==============================");
        //获得对象引用
        System.out.println(days[0].getDeclaringClass());

        System.out.println("==============================");
        //MONDAY,枚举推荐使用toString
        System.out.println(days[0].name() +"---" +days[0]);

        System.out.println("==============================");
        //返回枚举实例
        Day day = Day.valueOf("MONDAY"); //编译器添加的静态方法
        Day day1 = Day.valueOf(Day.class, "TUESDAY"); //Enum抽象类提供的方法
        System.out.println(day.getClass().getTypeName());
        System.out.println(day1);
    }
}
